package com.showdor.springboot;

/**
 * @author showdor
 * @email chuanqi@outlook.com
 * @date 2023/7/4
 */

import java.io.*;

public class WriterDataFile {

    private static String path = "E:\\kafkadata_SDFD.csv";

    public static void writeData(String strvalue) {
        FileWriter fw;
        try {
            fw = new FileWriter(path, true);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(strvalue + "\r\n");
            bw.flush();
            bw.close();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static void main(String[] args) {
        String[] arr = {"select * from dual", " Select f1,f2 from tb", "select * from tb for update", "insert into tb value (1,2)", " update tb set f1=1 where f2=2", " delete from tb where id=10", " SELET a,b,c from tb where d=5", "SELect a.*,b.* from a left join b on a.id=b.aid", " select A from B | delete", " selectsysdate from dual", " select insert from tb"};
        for (String text : arr) {
            if (isSelect(text)) {
                System.out.println(text);
            }
        }
    }

    private static boolean isSelect(String sql) {
        return sql.matches("(?i)^\\s*select\\s+((?!insert|delete|update|truncate|drop).)+$");    }
}
